//
//  ImageAndLabelCollectionViewCell.m
//  Taste
//
//  Created by 徐昊 on 16/8/31.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ImageAndLabelCollectionViewCell.h"
#import "Content.h"
#import "NSString+Vali.h"
#import "UIImageView+WebCache.h"
#import "DailyInformationViewController.h"
#import "DailyInformationRes.h"
#import "HomePageDetailMore.h"
#import "Latestcon.h"
#import "ResturantMore.h"
#import "MasterCookBookMore.h"
@interface ImageAndLabelCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *picture;

@property (weak, nonatomic) IBOutlet UIImageView *video;

@end

@implementation ImageAndLabelCollectionViewCell
- (void)setContent:(Content *)content {
    _content = content;
    [self.picture sd_setImageWithURL:[NSURL URLWithString:[NSString imageWebWithStr:_content.pic]] placeholderImage:[UIImage imageNamed:@"IMG_Universal_Placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    self.label.text = _content.title;
    if ([_content.video isKindOfClass:[NSString class]]) {
        
    } else {
        if ([_content.video isEqual:@(1)]) {
            self.video.alpha = 1;
        } else {
            self.video.alpha = 0;
        }
    }
}
- (void)picAlpha {
    if ([_content.video isKindOfClass:[NSString class]]) {
        
    } else {
        if ([_content.video isEqual:@(1)]) {
            self.video.alpha = 1;
        } else {
            self.video.alpha = 0;
        }
    }
}
- (void)setRes:(DailyInformationRes *)res {
    _res = res;
    [self.picture sd_setImageWithURL:[NSURL URLWithString:[NSString imageWebWithStr:_res.pic]] placeholderImage:[UIImage imageNamed:@"IMG_Universal_Placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    self.label.text = _res.title;
    if ([_res.video isKindOfClass:[NSString class]]) {
        if ([res.video isEqualToString:@""]) {
            self.video.alpha = 0;
        } else {
            self.video.alpha = 1;
        }
    } else {
        if ([_res.video isEqual:@(1)]) {
            self.video.alpha = 1;
        } else {
            self.video.alpha = 0;
        }
    }
}
- (void)setLatestCon:(Latestcon *)latestCon {
    _latestCon = latestCon;
    [self.picture sd_setImageWithURL:[NSURL URLWithString:[NSString imageWebWithStr:_latestCon.pic]] placeholderImage:[UIImage imageNamed:@"IMG_Universal_Placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    self.label.text = latestCon.title;
    if ([_latestCon.has_video isKindOfClass:[NSString class]]) {
        if ([_latestCon.has_video isEqualToString:@"1"]) {
            self.video.alpha = 1;
        } else {
            self.video.alpha = 0;
        }
    } else {
        if ([_content.video isEqual:@(1)]) {
            self.video.alpha = 1;
        } else {
            self.video.alpha = 0;
        }
    }
}
- (void)setMore:(HomePageDetailMore *)more {
    _more = more;
    [self.picture sd_setImageWithURL:[NSURL URLWithString:[NSString imageWebWithStr:_more.pic]] placeholderImage:[UIImage imageNamed:@"IMG_Universal_Placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    self.label.text = more.short_content;
    if ([_more.has_video isKindOfClass:[NSString class]]) {
        if ([_more.has_video isEqualToString:@"1"]) {
            self.video.alpha = 1;
        } else {
            self.video.alpha = 0;
        }
    } else {
        if ([_content.video isEqual:@(1)]) {
            self.video.alpha = 1;
        } else {
            self.video.alpha = 0;
        }
    }
}
- (void)setCookBookMore:(MasterCookBookMore *)cookBookMore {
    _cookBookMore = cookBookMore;
    [self.picture sd_setImageWithURL:[NSURL URLWithString:[NSString imageWebWithStr:_cookBookMore.pic]] placeholderImage:[UIImage imageNamed:@"IMG_Universal_Placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    self.label.text = cookBookMore.title;
    // 判断小图标
    if ([_cookBookMore.video isEqualToString:@""]) {
        self.video.alpha = 0;
    } else {
        self.video.alpha = 1;
    }
}
- (void)setMoreInfo:(ResturantMore *)moreInfo {
    _moreInfo = moreInfo;
    [self.picture sd_setImageWithURL:[NSURL URLWithString:[NSString imageWebWithStr:_moreInfo.pic]] placeholderImage:[UIImage imageNamed:@"IMG_Universal_Placeholder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    self.label.text = moreInfo.title;
    self.video.alpha = 0;
}
- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
    _picture.contentMode = UIViewContentModeScaleAspectFill;
    _picture.clipsToBounds = YES;
}

@end
